package com.fengmi.controller;


import com.fengmi.service.SysPermissionService;
import com.fengmi.dto.PageDTO;
import com.fengmi.entity.SysPermission;
import com.fengmi.service.SysPermissionService;
import com.fengmi.vo.PageResultVO;
import com.fengmi.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 123
 * @Date 2022/1/25 10:03
 * @Version 1.0
 */

@RestController
@RequestMapping("permission")
@CrossOrigin
@Api(tags = "权限管理")
public class SysPermissionController {

    @Autowired
    private SysPermissionService permissionService;

    @PostMapping("page")
    @ApiOperation("分页条件查询权限信息")
    public PageResultVO<SysPermission> page(@RequestBody @ApiParam("分页条件查询实体类") PageDTO<SysPermission> pageDTO) {
        return permissionService.findPermissionByPage(pageDTO);
    }

    @GetMapping
    @ApiOperation("查询权限及其子权限信息")
    public ResultVO findCascade() {
        return permissionService.selectPermissionCascade();
    }

    @PostMapping("save")
    public ResultVO save(@RequestBody SysPermission sysPermission) {
        return permissionService.saveAddPermission(sysPermission);
    }

    @PutMapping("update")
    @ApiOperation("修改权限")
    public ResultVO updatePermission(@RequestBody SysPermission sysPermission) {
        return permissionService.updatePermission(sysPermission);
    }

    @DeleteMapping("delete/{permCode}")
    @ApiOperation("删除权限")
    public ResultVO deletePermission(@PathVariable String permCode) {
        return permissionService.deletePermission(permCode);
    }


}
